//
//  TopNewsCell.m
//  SportSocial
//
//  Created by yull on 14/12/21.
//  Copyright (c) 2014年 yull. All rights reserved.
//

#import "TopNewsCell.h"
#import "UIImageView+WebCache.h"

@implementation TopNewsCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        CGRect rect = CGRectMake(10, 0, self.contentView.width - 20, 40);
        self.newsTitleLabel = [[UILabel alloc] initWithFrame:rect];
        self.newsTitleLabel.backgroundColor = [UIColor clearColor];
        self.newsTitleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        self.newsTitleLabel.font = [UIFont systemFontOfSize:15.0f];
        self.newsTitleLabel.backgroundColor = [UIColor blackColor];
        [self.contentView addSubview:self.newsTitleLabel];
    
        CGFloat width = (SCREEN_WIDTH - 30)/3;
        CGFloat height = 76.0f;
        
        rect = CGRectMake(10, self.newsTitleLabel.bottom, width, height);
        self.leftImageView = [[UIImageView alloc] initWithFrame:rect];
        [self.contentView addSubview:self.leftImageView];
        
        rect.origin.x = self.leftImageView.right + 5;
        self.centerImageView = [[UIImageView alloc] initWithFrame:rect];
        [self.contentView addSubview:self.centerImageView];
        
        rect.origin.x = self.centerImageView.right + 5;
        self.rightImageView = [[UIImageView alloc] initWithFrame:rect];
        [self.contentView addSubview:self.rightImageView];
    }
    return self;
}

+ (CGFloat)defaultTopNewsCellHeight
{
    return 50.0f + 76.0f;
}

- (void)drawCellWithTitle:(NSString *)title imageArray:(NSArray *)imageArray
{
    self.newsTitleLabel.text = title;
    
    self.leftImageView.image = nil;
    self.centerImageView.image = nil;
    self.rightImageView.image = nil;
    
    if (imageArray.count > 0) {
        [self.leftImageView sd_setImageWithURL:[NSURL URLWithString:imageArray.firstObject]];
    }
    
    if (imageArray.count > 1) {
        [self.centerImageView sd_setImageWithURL:[NSURL URLWithString:[imageArray objectAtIndex:1]]];
    }
    
    if (imageArray.count > 2) {
        [self.rightImageView sd_setImageWithURL:[NSURL URLWithString:imageArray.lastObject]];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
